#include <iostream>
#include "mysqlite3.h"

using namespace std;

int cb(void* relayed_param,int col_num, char** col_val,char** col_name)
{
    if ( col_val == NULL)
    {
        cout<<"col_val NULL"<<endl;
        return 0;
    }
    if ( col_name == NULL)
    {
        cout<<"col_name NULL"<<endl;
        return 0;
    }

    for(int i = 0; i < col_num; ++i)
    {
        if ( (col_name + i) != NULL )
            cout<<*(col_name+i)<<"\t";
        else
            cout<<"col_"<<i<<"\t";
    }

    cout<<endl;

    for(int i = 0; i < col_num; ++i)
    {
        if ( (col_val + i) != NULL )
            cout<<*(col_val +i)<<"\t";
        else
            cout<<"NULL"<<"\t";
    }
    cout<<endl;
    return 0;
}

int main(int argc, char* argv[])
{
    Mysqlite3 db;

    string errmsg;
    //if( !db.create_open("./test.db") )
    //{
    //    cout<<"create_open error"<<endl;
    //    return 0;
    //}

    //string createtable("create table test(\
    //    id varchar(32),\
    //    name varchar(32),\
    //    primary key(id));");

    //if ( !db.exec(createtable,cb,errmsg))
    //{
    //    cout<<"error:"<<errmsg<<endl;
    //    return 0;
    //}
    //
    if ( !db.open("./test.db") )
    {
        cout<< "open failed"<<endl;
        return 0;
    }

    string insert("insert into test(id,name) values(\"2\",\"hello\");");
    if ( !db.exec(insert,cb,errmsg))
    {
        cout<<"insert error:"<<errmsg<<endl;
        return 0;
    }
    
    string select("select * from test;");
    if ( !db.exec(select,cb,errmsg) )
    {
        cout<<"select error:"<<errmsg<<endl;
        return 0;
    }

    return 0;
}







